<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2016-06-23
  Time: 下午 12:29
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html lang="cmn-Hans-CN">
<head>
    <meta charset="utf-8">
    <title>店铺申请</title>
    <link href="/static/bootstrap/bootstrap.css" rel="stylesheet" type="text/css"/>
    <style>
        .control-label{
            padding-top: 7px;
            margin-bottom: 0;
            text-align: right;
        }
    </style>
</head>
<body>
<nav class="navbar navbar-default">
    <div class="container-fluid">
        <div class="navbar-header">
            <a class="navbar-brand" href="#">店铺申请</a>
        </div>
    </div>
</nav>

<div style="padding: 10px;">
    <div class="form-horizontal" id="register">

        <div class="form-group">
            <label class="control-label col-xs-4 ">后台账号：</label>
            <div class="col-xs-7">
                <input type="text" class="form-control" name="userName" placeholder="登录后台的账号">
            </div>
        </div>

        <div class="form-group">
            <label class=" control-label col-xs-4">后台密码：</label>
            <div class="col-xs-7">
                <input type="password" class="form-control" name="password" placeholder="密码">
            </div>
        </div>

        <hr>

        <div class="form-group hide">
            <label class=" control-label col-xs-4">申请人ID：</label>
            <div class="col-xs-7">
                <input type="text" class="form-control" name="userId" value="${userId}" placeholder="">
            </div>
        </div>

        <div class="form-group">
            <label class=" control-label col-xs-4">店铺名称：</label>
            <div class="col-xs-7">
                <input type="text" class="form-control" name="name" placeholder="店铺名称">
            </div>
        </div>

        <div class="form-group">
            <label class=" control-label col-xs-4">所在省：</label>
            <div class="col-xs-7">
                <input type="text" class="form-control" name="province" placeholder="例如：山东省">
            </div>
        </div>

        <div class="form-group">
            <label class=" control-label col-xs-4">所在市：</label>
            <div class="col-xs-7">
                <input type="text" class="form-control" name="city" placeholder="例如：济南市">
            </div>
        </div>

        <div class="form-group">
            <label class=" control-label col-xs-4">所在区县：</label>
            <div class="col-xs-7">
                <input type="text" class="form-control" name="district" placeholder="例如：天桥区">
            </div>
        </div>

        <div class="form-group">
            <label class=" control-label col-xs-4">详细街道：</label>
            <div class="col-xs-7">
                <input type="text" class="form-control" name="address" placeholder="例如：XX街道XX号">
            </div>
        </div>

        <hr>

        <div class="form-group" align="center">
            <div class="col-xs-offset-2 col-xs-10">
                <button type="button" class="btn btn-primary col-xs-8" onclick="register()">申请开通</button>
            </div>
        </div>
    </div>
</div>
</body>
</html>
<script src="/static/js/jquery-1.12.3.js"></script>
<script src="/static/bootstrap/bootstrap.min.js"></script>
<script src="/static/js/jquery.md5.js"></script>
<script>

    function register() {
        var param = formParams("register");

        param["password"] = $.md5(param["password"] );

        post("/app/shop/register", param, function (data) {
            if (data.success) {
                alert("提交成功，请等待后台通过申请");
                window.location.reload();
            } else {
                if (data.code == 2) {
                    alert("您已经提交过申请。");
                } else {
                    alert("提交失败！请检查提交内容。");
                }

            }
        });
    }


    function formParams(_formId) {

        var nodes = $("#" + _formId).find("input[type='text'],input[type='password']" +
                ",input[type='hidden'],input[type='radio']:checked," +
                "input[type='checkbox']:checked,textarea,select");
        var params = {};

        for (var i = 0; i < nodes.length; i++) {

            var e = $(nodes[i]);
            var name = e.attr("name");
            if (name != undefined) {
                if (params[name] == undefined) {
                    params[name] = e.val();
                } else {
                    params[name] += "," + e.val();
                }
            }

        }
        return params;
    }


    /**
     * ajax post 提交方法
     * @param url
     * @param param
     * @param success
     */
    function post(_url, _param, _success) {
        var time;
        $.ajax({
            url: _url,
            type: "post",
            data: _param,
            dataType: "json",
            async: true,// false:同步请求 默认true
            success: _success,
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                console.log(XMLHttpRequest.responseText);
            },
            beforeSend: function (XMLHttpRequest) {
                time = new Date().getTime();
            },
            complete: function (XMLHttpRequest, textStatus) {
                var time2 = new Date().getTime();
                console.log("本次ajax操作耗时：" + (time2 - time) + "毫秒；");
            }
        });
    }
</script>
